let vm = new Vue({
    el: '.main-container',  //选中整个main
    data() {
        return {
            page: {},
            isShow: false,
            name: '',
            condition: {
                pid: '',
                name: ''
            },
            // highLight:false,
            setting: {
                data: {
                    simpleData: {
                        enable: true,
                        pIdKey: "parentId",//父节点的名字
                        idKey: "id" //子节点的名字
                    },//开启简单树
                    key: {
                        title: 'ztree',
                        url:"ppt"
                    }
                },
                callback: {//回掉函数
                    onClick: this.onClick
                },
                view: {
                    fontCss: this.fontCss
                }
            },
            nodes: []
        }
    },
    methods: {
        selectPage: function (start = 1, pageSize = 5) {
            this.page = {};
            axios({
                url: `/guguanjia/manager/menu/selectPage/${start}/${pageSize}`,   //相对路径同样受到base标签影响
                params: this.condition
            }).then(
                response => {  //省略function关键字  自动传递上下文中的this
                    //this.apps = response.data.obj.list;
                    this.page = response.data.obj
                }
            ).catch(error => {
                console.log(error.message);
            })
        },
        selectAllRole: function () {
            this.page = {};
            axios({
                url: `/guguanjia/manager/menu/getParentMenus`,   //相对路径同样受到base标签影响
            }).then(
                response => {  //省略function关键字  自动传递上下文中的this
                    //this.apps = response.data.obj.list;
                    this.roles = response.data.obj;
                }
            ).catch(error => {
                console.log(error.message);
            })
        },
        init: function () {
            axios({
                url: "/guguanjia/manager/menu/getParentMenus" //相对路径同样受到base标签影响
            }).then(
                response => {  //省略function关键字  自动传递上下文中的this
                    //this.apps = response.data.obj.list;
                    this.nodes = response.data.obj
                    this.nodes[this.nodes.length] = {'id': 0, 'name': '全部单位', 'open': true};
                    $.fn.zTree.init($("#treeMenu"), this.setting, this.nodes);
                }
            ).catch(error => {
                console.log(error.message);
            })
            // console.log(tree)
        },

        fontCss: function (treeID, treeNode) {
            return treeNode.highLight ? {'color': 'red'} : {'color': 'black'};
        },
        onClick: function (event, treeMenu, TreeNode) {
            if (TreeNode.id === 0) {
                this.selectAll();
            } else {
                this.condition = {};
                this.condition.pid = TreeNode.id;
                this.selectPage();
                this.condition = {};
            }
        },

        selectAll: function () {
            //清空查询条件
            this.condition = {};
            this.selectPage();
        },
        toUpdate: function (menu) {
            layer.obj = menu;
            layer.open({
                type: 2,
                title: '编辑',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['70%', '70%'],
                content: 'menu/menu-save.html',
                end: () => {
                    this.selectAll();
                    this.init();
                }
            });
        },
        toAdd: function () {
            layer.open({
                type: 2,
                title: '工单详情',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['70%', '70%'],
                content: 'area/add.html',
                end: () => {
                    this.selectAll();
                    this.init();
                }
            });
        },
        deleteById: function (id) {
            layer.confirm('确认是否要删除？', {
                btn: ['是', '否'] //按钮
            }, () => {
                axios.put(`/guguanjia/manager/menu/deleteById/${id}`).then(
                    (result) => {
                        if (result.data.success) {
                            layer.msg(result.data.msg);
                            this.selectPage(this.page.pageNum);
                            this.init();
                        } else {
                            layer.msg("删除失败");
                        }
                    }
                ).catch((error) => {
                    layer.msg("删除失败");
                })
            }, function () {
                layer.msg("取消")
            });
        },
        todetil: function (menu) {
            layer.obj = menu;
            layer.open({
                type: 2,
                title: '详情',
                maxmin: true,
                shadeClose: true, //点击遮罩关闭层
                area: ['60%', '60%'],
                content: 'menu/menu-detail.html',
            });
        },
    },
    created: function () {
        this.selectPage();
        // this.selectAllRole();
        //console.log(this.page)
    },
    mounted: function () {//在ul节点挂载后初始化树
        this.init();
    }
});